<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;

class Accounts extends Model
{
    //
	protected $table='accounts';
	protected $fillable=['id','name','account_day','type','statu','status','create_uid'];
	protected $hidden=[];

	public function lists($where){
		$res=$this->where(function ($query) use($where){
			$query->where(['company_id'=>$where['company_id']]);
			if($where['name'] !=null){
				$query->where('name','like','%'.$where['name'].'%');
			}
			if($where['start_time'] !=null){
				$query->where('created_at','>',$where['start_time']);
			}
			if($where['end_time'] != null){
				$query->where('created_at','<',$where['end_time']);
			}
			if($where['status_'] !=null){
				$query->where(['status'=>$where['status_']]);
			}
			if($where['status'] !=null){
				$query->where(['statu'=>$where['status']]);
			}
		})->with('userInfo')->with('configuration_status')->paginate(config('app.config'));



		return $res;
	}

	public function userInfo(){
		return $this->belongsTo('App\Model\Users','create_uid');
	}

	public function configuration_status(){
		return $this->belongsTo('App\Model\Configuration_status','statu','configuration_id');
	}
}
